import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sainbainu/common/services/publish.dart';

import 'index.dart';

class HomeController extends GetxController
    with GetSingleTickerProviderStateMixin {
  HomeController();

  final state = HomeState();

  Worker? worker;

  /// 在 widget 内存中分配后立即调用。
  @override
  void onInit() {
    super.onInit();

    state.tabController = TabController(length: 2, vsync: this);

    worker = ever(PublishService.to.isPublished, (callback) {
      if (callback) {
        state.tabController.animateTo(1);
      }
    });
  }

  /// 在 onInit() 之后调用 1 帧。这是进入的理想场所
  @override
  void onReady() {
    print('home onReady================================');
    super.onReady();
  }

  /// 在 [onDelete] 方法之前调用。
  @override
  void onClose() {
    print('home onClose================================');
    super.onClose();
    state.tabController.dispose();
    worker?.dispose();
  }
}
